# import logging
# import time
#
# logger = logging.getLogger(__name__)
#
# class LoggingMiddleware:
#     def __init__(self, get_response):
#         print("===========init middleware ====================")
#         self.get_response = get_response
#
#     def __call__(self, request):
#         print("===========call middleware ====================")
#         # 记录请求开始时间
#         start_time = time.time()
#
#         # 处理请求
#         response = self.get_response(request)
#
#         # 计算耗时
#         duration = time.time() - start_time
#
#         # 记录日志
#         logger.info(
#             f"Path: {request.path} | "
#             f"Method: {request.method} | "
#             f"IP: {request.META.get('REMOTE_ADDR')} | "
#             f"Duration: {duration:.2f}s"
#         )
#         #打印logger.info里面的内容
#         print(
#             f"Path: {request.path} | "
#             f"Method: {request.method} | "
#             f"IP: {request.META.get('REMOTE_ADDR')} | "
#             f"Duration: {duration:.2f}s"
#         )
#         #打印请求参数
#         print("请求参数：", request.GET)
#         #打印请求头
#         print("请求头：", request.headers)
#         #打印请求体
#         print("请求体：", request.body)
#         #打印响应体
#         print("响应体：", response.content)
#         #打印响应状态码
#         print("响应状态码：", response.status_code)
#
#         return response